// pages/my/index.js
import { studentGetInfo } from "../../api/manage";

Page({
  data: {
    userInfo: {
      name:"",
      no:"",
      major:"",
      avatar:""
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
   onLoad() {
    const userID=wx.getStorageSync('userID');
     studentGetInfo(userID).then(res=>{
       console.log('个人信息',res);
       this.setData({
         userInfo:{
          name:res.data.studentName,
          no:res.data.studentNo,
          major:res.data.major,
          avatar:res.data.avatar
        }
       })
     });
  },

  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2 
      });
    }
    const userID=wx.getStorageSync('userID');
     studentGetInfo(userID).then(res=>{
       console.log('个人信息',res);
       this.setData({
         userInfo:{
          name:res.data.studentName,
          no:res.data.studentNo,
          major:res.data.major,
          avatar:res.data.avatar
        }
       })
     });
  },

  onItemClick:function(e){
    console.log(e.currentTarget.dataset.value)
    switch(e.currentTarget.dataset.value){
      case "my-info":
        wx.navigateTo({
          url: '/pages/edit_info/index',
        });break;
      case "academic-growth":wx.navigateTo({
        url: '/pages/academic_growth/index',
      });break;
      case "school-timetable":wx.navigateTo({
        url: '/pages/school_timetable/index',
      });break;
      case "query-results":wx.navigateTo({
        url: '/pages/query_results/index',
      });break;
      case "about-us":wx.navigateTo({
        url: '/pages/about_us/index',
      });break;
    };
  }
});
